#ifndef _ECX_DECODER_H_
#define _ECX_DECODER_H_

typedef struct {
	char *(*get_upload_dir)(void);
	ECMBOOL (*reader)(ecm_ptr_t ctx, char *buf, ecm_size_t size);
	void (*ungetc)(ecm_ptr_t ctx, char c);
	const char *(*get_content_type)(ecm_ptr_t);
	char *(*get_GET_query)(ecm_ptr_t ctx);
	char *(*get_POST_query)(ecm_ptr_t ctx);
	char *(*get_cookie)(ecm_ptr_t ctx);
} ecd_ops_t;

typedef struct {
	ecd_ops_t	*ops;
	ecm_ptr_t	ctx;
	char		*boundary;
	ecm_size_t	boundary_len;
	ecm_hashtable_t	NVs;
	ecm_hashtable_t	NVs_cookie;
	ecm_hashtable_t	NFs;
	ecm_hashtable_t	NFs_temp;
	char	*queries[3];
} ecd_t;

extern ecd_t *ecd_init(ecd_ops_t *ops, ecm_ptr_t ctx);
extern void ecd_finalize(ecd_t *);
extern const char *ecd_get(ecd_t *, const char *name);
extern ecm_ptrs_t *ecd_gets(ecd_t *, const char *name);
extern ecm_int32 ecd_geti(ecd_t *, const char *name);
extern const char *ecd_first(ecd_t *, const char **pname, ecm_ht_iterator_t *piter);
extern const char *ecd_next(ecd_t *, const char **pname, ecm_ht_iterator_t *piter);
ECMBOOL ecd_file(ecd_t *, const char *name, const char **ppath);
void ecd_file_insert(ecd_t *, const char *name, const char *path);

extern const char *ecd_get_cookie(ecd_t *, const char *name);
extern const char *ecd_first_cookie(ecd_t *, const char **pname, ecm_ht_iterator_t *piter);
extern const char *ecd_next_cookie(ecd_t *, const char **pname, ecm_ht_iterator_t *piter);

char *ecd_URLencode(const char *);
char *ecd_URLdecode(char *);

#endif
